﻿using System;

namespace ShapeFactoryExample
{
    public abstract class Shape
    {
        public abstract double Area();
    }

    public class Circle : Shape
    {
        private double radius;

        public Circle(double radius)
        {
            this.radius = radius;
        }

        public override double Area()
        {
            return Math.PI * radius * radius;
        }
    }

    // 矩形类
    public class Rectangle : Shape
    {
        private double width;
        private double height;

        public Rectangle(double width, double height)
        {
            this.width = width;
            this.height = height;
        }

        public override double Area()
        {
            return width * height;
        }
    }

    // 正方形类
    public class Square : Shape
    {
        private double side;

        public Square(double side)
        {
            this.side = side;
        }

        public override double Area()
        {
            return side * side;
        }
    }

   

    public class ShapeFactory
    {
        private Random random = new Random();

        public Shape CreateRandomShape()
        {
            int shapeType = random.Next(0, 3);

            double size = random.Next(101) +1;
            double size2 = random.Next(101) + 1;

            switch (shapeType)
            {
                case 0: // 圆形
                    return new Circle(size);
                case 1: // 矩形
                    return new Rectangle(size, size2);
                case 2: // 正方形
                    return new Square(size);
                default:
                    throw new InvalidOperationException();
            }
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            ShapeFactory factory = new ShapeFactory();
            double _area = 0;

            // 创建10个随机形状并计算总面积
            for (int i = 0; i < 10; i++)
            {
                Shape shape = factory.CreateRandomShape();
                _area += shape.Area();
            }

            Console.WriteLine($"Total area of 10 random shapes: {_area}");
        }
    }
}